package com.admin.web;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.admin.bean.Grades;
import com.admin.bean.SCClass;
import com.admin.bean.SCStudent;
import com.admin.bean.Student;
import com.admin.mapper.SCStudentMapper;

@Controller
@RequestMapping("sc")
public class ScController {
	
	@Autowired
	protected SCStudentMapper studentMapper;
	
//	@ModelAttribute
//	public void scCommenGrade(Model model) {
//		Grades grade1 = new Grades("软件L071班", 1);
//		Grades grade2 = new Grades("软件L072班", 2);
//		Grades grade3 = new Grades("软件L073班", 3);
//		List<Object> list2 = new ArrayList<Object>();
//		list2.add(grade1);
//		list2.add(grade2);
//		list2.add(grade3);
//		model.addAttribute("list2", list2);
//	}
	@ModelAttribute
	public void scClass(Model model) {
		SCClass class1 = new SCClass("软件L071", "CL001", "S001");
		SCClass class2 = new SCClass("软件L072", "CL002", "S001");
		SCClass class3 = new SCClass("软件L073", "CL003", "S001");
		List<Object> list2 = new ArrayList<Object>();
		list2.add(class1);
		list2.add(class2);
		list2.add(class3);
		model.addAttribute("list2", list2);
	}

	@RequestMapping("home")
	public String home() {
//		List<Object> list = new ArrayList<Object>();
//		model.addAttribute("list", list);
		return "sc/home";
	}
	
//	@RequestMapping("stuList")
//	@ResponseBody
//	@Transactional
//	private Object stuList(){
//		
//		List<SCStudent> stulist = studentMapper.list();
//		return stulist;
//	}
	
	
	@Transactional
	@ResponseBody
	@RequestMapping("stuList")
	private Object stuList(String id){
		
		List<SCStudent> stulist = studentMapper.findById(id);
		return stulist;
	}
	
	

//	@RequestMapping("list")
//	public String list(@RequestParam(value = "id", required = false) Integer id, Model model) {
//		List<Object> list = new ArrayList<Object>();
//		if (id == null) {
//			return "sc/list";
//		}
//		switch (id) {
//		case 1:
//			list.add(new Student("张三", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("lisi", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wangwu", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			break;
//		case 2:  
//			list.add(new Student("张三1", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("lisi1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wangwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("张三1", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("lisi1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wangwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			break;
//		case 3:
//			list.add(new Student("张21", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("li2si1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wa2ngwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("张2三1", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("li2si1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wa2ngwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			break;
//		default:
//			break;
//		}
//		
//		model.addAttribute("list", list);
//		return "sc/list";
//	}
//	
//	
//	@RequestMapping("listObj")
//	@ResponseBody
//	public Object listObj(Integer id) {
//		List<Object> list = new ArrayList<Object>();
//		if (id == null) {
//			return list;
//		}
//		switch (id) {
//		case 1:
//			list.add(new Student("张三", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("lisi", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wangwu", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			break;
//		case 2:
//			list.add(new Student("张三1", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("lisi1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wangwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("张三1", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("lisi1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wangwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			break;
//		case 3:
//			list.add(new Student("张21", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("li2si1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wa2ngwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("张2三1", "男", 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("li2si1", "男", 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			list.add(new Student("wa2ngwu1", "男", 3, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10));
//			break;
//		default:
//			break;
//		}
//		return list;
//	}
}